<template>
  <div
    v-infinite-scroll="loadMore"
    infinite-scroll-disabled="disabledScroll"
    infinite-scroll-distance="10"
    infinite-scroll-immediate-check="false"
    class="suggest">
    <div class="top">
      <mt-header>
        <mt-button slot="left" icon="back" @click="handleBack"></mt-button>
      </mt-header>
      <img src="./top.png">
    </div>
    <div class="short-cut">
      <router-link to="/suggest/praise?type=praise" class="item">
        <i class="xffont xf-biaoyang"></i>
        <span>我要表扬</span>
      </router-link>
      <router-link to="/suggest/praise?type=complaint" class="item">
        <i class="xffont xf-tousu"></i>
        <span>我要投诉</span>
      </router-link>
      <router-link to="/suggest/praise?type=suggest" class="item">
        <i class="xffont xf-jianyi"></i>
        <span>我要建议</span>
      </router-link>
      <router-link to="/suggest/letter" class="item">
        <i class="xffont xf-jianyi1"></i>
        <span>主任信箱</span>
      </router-link>
    </div>
    <mt-navbar v-model="selected">
      <mt-tab-item :id="1">最新表扬</mt-tab-item>
      <mt-tab-item :id="2">最新投诉</mt-tab-item>
      <mt-tab-item :id="3">最新建议</mt-tab-item>
    </mt-navbar>
    <div>
      <div @click="detail(item)" class="list-item" v-for="(item, index) in list" :key="index">
        <div class="send">
          <div class="top">
            <span class="desc">编号：{{item.ess002}}</span>
            <span class="desc">{{$dateFormat(item.ess010).format('YYYY-MM-DD')}}</span>
          </div>
          <div class="tit">{{item.esa201}}</div>
          <div class="con">{{item.esa202}}</div>
        </div>
        <div class="back" >
          <div class="top">
            <span>状态：<span class="pending" v-if="Number(item.esb001) === 1">未回复</span><span class="response" v-else>已回复</span></span>
            <span v-if="Number(item.esb001) === 2">回复日期：{{$dateFormat(item.esb004).format('YYYY-MM-DD')}}</span>
          </div>
          <div class="con" v-show="Number(item.esb001) === 2">回复内容：{{item.esb002}}</div>
        </div>
      </div>
    <loading-text v-if="loading"></loading-text>
    <finish-text v-if="noMore"></finish-text>
    <empty v-if="empty"></empty>
    <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router" @refresh="refresh"></router-view>
    </transition>
  </div>
</template>
<script>
  import LoadingText from '../../components/loading-text/loading-text.vue'
  import FinishText from '../../components/finish-text/finish-text.vue'
  import {http} from '../../common/js/util'
  import {infinite} from '../../common/js/mixin'
  import Empty from '../../components/empty/empty.vue'
  import DefaultLayout from '../../layouts/default-layout/default-layout'
  import {STORAGE_TYPE} from '../../common/js/config'
  export default {
    computed: {
      ...infinite
    },
    components: {
      DefaultLayout,
      Empty,
      FinishText,
      LoadingText},
    data() {
      return {
        selected: 1,
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
      /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    methods: {
      handleBack() {
        this.$router.back()
      },
      refresh() {
        this.page = 1
        this.loadMore()
      },
      loadMore() {
        if (this.page === 1) this.list = []
        http({
          method: 'post',
          url: '/sapi/iwantsay/say/list',
          data: {
            type: this.selected,
            page: this.page,
            pageSize: this.size
          }
        }, loading => {
          this.loading = loading
        }).then(res => {
          this.list = this.list.concat(res.data.list)
          this.total = res.data.pager.totalRecord
          this.page++
        })
      },
      detail(val) {
        let titleCont = '我要表扬'
        if (this.selected === 1) {
          titleCont = '我要表扬'
        } else if (this.selected === 2) {
          titleCont = '我要投诉'
        } else {
          titleCont = '我要建议'
        }
        /*
        * title: '主任信箱',
          发送标题: val.esa201,
          发送内容: val.esa202,
          发送时间: val.aae036,
          状态: Number(val.esb001),
          回复内容: val.esb002,
          回复时间: val.esb004
        * */
        sessionStorage.setItem(STORAGE_TYPE.suggest, JSON.stringify(Object.assign({title: titleCont}, val)))
        this.$router.push({
          name: 'suggestDetail'
        })
      }
    },
    created() {
      this.loadMore()
      this.$watch('selected', () => {
        setTimeout(() => {
          this.page = 1
          this.loadMore()
        }, 20)
      })
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../common/style/variable";
  .suggest{
    height: 100%;
    overflow-y: auto;
    .top{
      position: relative;
      img{
        width: 100%;
        display: block;
      }
    }
  }
  .mint-header{
    background-color: rgba(0,0,0,0);
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
  }
  .short-cut{
    display: flex;
    margin: 0 0 2px 0;
    padding: .14rem 0;
    background: #fff;
    flex-wrap: wrap;
    .item{
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: .1rem .1rem;
      text-align: center;
      border-radius: 5px;
      @include active;
      .xffont{
        font-size: .5rem;
        color: $primary;
      }
      span{
        margin: .1rem 0 0 0;
      }
    }
  }
  .mint-navbar{
    margin: .15rem 0 0 0;
    border-bottom: 1px solid #ededed;
  }
  .list-item{
    background: #fff;
    padding: .2rem;
    display: block;
    &:not(:last-child){
      margin: 0 0 .15rem 0;
    }
    .send{
      padding: 0 0 .2rem 0;
      border-bottom: 1px solid #ededed;
      .top{
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666;
        padding: 0 0 .1rem 0;
      }
      .tit{
        width: 100%;
        font-size: .32rem;
        color: #000;
        @include ellipsis;
      }
      .con{
        padding: .05rem 0 0 0;
        width: 100%;
        color: #333;
        @include ellipsis;
      }
    }
    .back{
      padding: .2rem 0 0 0;
      .top{
        color: #333;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .con{
        color: #333;
        width: 100%;
        @include ellipsis;
        padding: .1rem 0 0 0;
      }
    }
  }
  .response{
    color: $primary;
  }
  .pending{
    color: $danger;
  }
</style>
